/**
 * 
 */
package com.alcatel.staj.janjan.swing.ui;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JButton;

import com.alcatel.staj.janjan.exception.ObjectNotFound;
import com.alcatel.staj.janjan.model.Personel;
import com.alcatel.staj.janjan.service.PersonelManager;

/**
 * @author reyhan
 *
 */
public class Login extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JLabel lblname = null;
	private JLabel lblpassword = null;
	private JTextField txtname = null;
	private JTextField txtpassword = null;
	private JButton jButton = null;

	/**
	 * This is the default constructor
	 */
	public Login() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			lblpassword = new JLabel();
			lblpassword.setBounds(new Rectangle(26, 64, 68, 23));
			lblpassword.setText("password");
			lblname = new JLabel();
			lblname.setBounds(new Rectangle(25, 23, 62, 24));
			lblname.setText("Name");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(lblname, null);
			jContentPane.add(lblpassword, null);
			jContentPane.add(getTxtname(), null);
			jContentPane.add(getTxtpassword(), null);
			jContentPane.add(getJButton(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes txtname	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtname() {
		if (txtname == null) {
			txtname = new JTextField();
			txtname.setBounds(new Rectangle(108, 25, 95, 22));
		}
		return txtname;
	}

	/**
	 * This method initializes txtpassword	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtpassword() {
		if (txtpassword == null) {
			txtpassword = new JTextField();
			txtpassword.setBounds(new Rectangle(109, 61, 93, 24));
		}
		return txtpassword;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(92, 108, 65, 22));
			jButton.setText("login");
			jButton.addMouseListener(new java.awt.event.MouseAdapter() {
				
				public void mouseClicked(java.awt.event.MouseEvent e) {
					//System.out.println("mouseClicked()"); 
					Personel personel=new Personel();
					String name=txtname.getText();
					String password=txtpassword.getText();
					try{
					PersonelManager manager=PersonelManager.getInstance();
					personel=manager.login(name, password);
					if(personel.getRole()==1)
					{
						Anasayfa anasayfa=new Anasayfa();
						anasayfa.setVisible(true);
						anasayfa.jpnladmin.setVisible(true);
					}
					else if(personel.getRole()==0)
					{
						Anasayfa anasayfa=new Anasayfa();
						anasayfa.setVisible(true);
						anasayfa.jpnluser.setVisible(true);
						
					}
					}
					catch(ObjectNotFound o)
					{
						o.printStackTrace();
					}
					
				}
				
				
			});
		}
		return jButton;
	}

}  //  @jve:decl-index=0:visual-constraint="214,13"
